$(function() {
	changeHeaderMenu(1);
	config.id = getUrlParam('id');
	loadData();
});

var config = {
	id: null
};

function loadData() {
	$.getJSON('/cloud_ifw/member/deviceinfobrow_getbyid.action', {
		deviceIndex: config.id
	}, function(data) {
		if(data.success && data.result)
			data = data.result;
		$('.deviceModel').html(data.deviceModel);
		var deviceSn = data.deviceSn;
    	var data2 = $.ajax({url: "/cloud_ifw/member/deviceinfobrow_getsnbymap.action?deviceSn=" + data.deviceSn, async: false }).responseText;
    	data2 = $.parseJSON(data2);
    	if(data2.success && data2.result)
    		deviceSn = data2.result;
		$('.deviceSn').html(deviceSn);
		// 状态
		var time = data.deviceActiveLast.time;
		var time_now = new Date().getTime();
		if(time_now - time < 300000) {
			$('.deviceStatus').html('<span style="color: green;">在线</span>');
		} else {
			$('.deviceStatus').html('<span style="color: red;">离线</span>');
		}
		$('.deviceVersion').html(data.deviceVersion);
		$('.deviceCpuModel').html(data.deviceCpuModel);
//		$('.deviceMemTotal').html(data.deviceMemTotal + 'kB');
		$('.deviceMemTotal').html(data.deviceMemTotal);
		var dut = data.deviceUptime;
		var dut_d = Math.floor(dut / 86400);
		dut = dut % 86400;
		var dut_h = Math.floor(dut / 3600);
		dut = dut % 3600;
		var dut_s = Math.floor(dut / 60);
		$('.deviceUptime').html(dut_d + '天' + dut_h + '时' + dut_s + '分');
		$('.deviceOnline').html(data.deviceOnline);
		$('.deviceCpuUsage').html(data.deviceCpuUsage + '%');
		$('.deviceMemUsage').html(data.deviceMemUsage + '%');
		$('.deviceTxTotal').html(toNetSpeed(data.deviceTxTotal));
		$('.deviceRxTotal').html(toNetSpeed(data.deviceRxTotal));
		$('.deviceIp').html(data.deviceIp);
		$('.deviceWanIp1').html(data.deviceWanIp1);
		$('.deviceWanIp2').html(data.deviceWanIp2);
		$('.deviceWanIp3').html(data.deviceWanIp3);
		var dal = data.deviceActiveLast;
		var dal_year = dal.year;
		dal_year += 1900;
		var dal_month = dal.month;
		dal_month += 1;
		if(dal_month < 10)
			dal_month = '0' + dal_month;
		var dal_date = dal.date;
		if(dal_date < 10)
			dal_date = '0' + dal_date;
		var dal_hours = dal.hours;
		if(dal_hours < 10)
			dal_hours = '0' + dal_hours;
		var dal_minutes = dal.minutes;
		if(dal_minutes < 10)
			dal_minutes = '0' + dal_minutes;
		var dal_seconds = dal.seconds;
		if(dal_seconds < 10)
			dal_seconds = '0' + dal_seconds;
		$('.deviceActiveLast').html(dal_year + '-' + dal_month + '-' + dal_date + ' ' + dal_hours + ':' + dal_minutes + ':' + dal_seconds);
	});
}